The Green Language

نویسنده

  • José de Oliveira Guimarães
چکیده

class Container public: abstract proc add( x : integer ) abstract proc get() : integerproc get() : integer proc empty() : boolean begin return getSize() == 0; end proc full() : boolean begin return getSize() == getMaxSize(); end abstract proc getSize() : integerproc getSize() : integer abstract proc getMaxSize() : integer; endproc getMaxSize() : integer; end Figura 3.4: Class Container for storing objects proc cast( ch : char ) : integer assert after result >= 0 and result <= 127; end 3.6 Abstract Classes A class in which some method bodies may not defined is called abstract. The class declaration is preceded by the keyword abstract and so are the methods not fully defined. Although the body of a method (its local variables and statements) may not be specified, its header should. As an example, the class Container of Figure 3.4 is abstract and the method bodies of put, get, getSize, and getMaxSize are missing. To fully define abstract classes we need to specify some features and restrictions, which is made below. • constructors, defined in Chapter 4, cannot be abstract; • some methods and instance variables may be fully defined and the methods may use other class methods; • an abstract class may not have any abstract method. It still is an abstract class as long as the keyword abstract precedes the word class in the class declaration; • constructors may be defined although an object of an abstract class cannot be created — abstract classes are made only to play the role of superclasses and as a design specification. 20 CAPÍTULO 3. CLASSES AND METHODS A variable whose type is an abstract class can be declared and it can refer to objects of subclasses of the abstract class; • all abstract methods must be in the public or subclass section. See Section 5.4 for the definition of subclass section. 3.7 Why Green Does Not Support Operator Overloading ? Operator overloading is the use of operators of the basic classes (+, *, <=, and, ...) as method names in normal classes. In general this makes the language more complex without adding no power to it. Other reasons for not supporting this feature are discussed next. When one defines a method proc +(other : T) : T in a class T, we assume + has the same semantics as the basic-class operator “+”. That is, “+” is free from side effects. The evaluation of “x + y” does not change the value of x or y if they are integers. It is tempting to introduce a slightly change to the semantics of a method proc +(other : Matrix) : Matrix of class Matrix in such a way the return value is self then saving the creation of a large Matrix object that would be returned by “+”. Parameter other would be added to self by Matrix::x then producing a side effect. This is the reason why normal classes cannot declare operators as methods. Besides the side-effect problem (semantics differences), there is another related to this: there is no simple way a method can emulate some operators like and and or of class boolean. These methods have short-circuit evaluation. This means an expression i < n and v[i] > 0 evaluates to false if i >= n, regardless of the result of v[i] > 0. Suppose operator and was added to a class Correct and ok is a variable of this class. The expression ok and v[i] > 0 would be equivalent to ok.and( v[i] > 0 ) and should return false if ok if false, without evaluating “v[i] > 0”. But by the semantics of method call the real parameter is always evaluated. For short, Green does not support operator overloading because of the semantic differences between basic classes and reference classes and because of the impossibility of simulating some operators. 3.8 Expanded Variables An instance or local variable may be declared as var clock : @Clock; to mean it obeys value instead of reference semantics, like the basic classes. The declaration alone allocates memory for the object, which need not to be dynamically allocated. Variables declared with @ are constants — it is a compiler error to use them in the left-hand side of an assignment. These @-variables correspond to variables of expanded classes in Eiffel or to non-pointer variables in C++. They are called expanded variables in Green. 3.8. EXPANDED VARIABLES 21 An expanded variable or @-variable should be initiated by sending to it an init message: clock.init(13, 52); This code replaces a call to method new of class Clock that would be made if clock were a regular variable: clock = Clock.new(13, 52); Messages init can only be sent to expanded variables. That will never cause an error because an expanded variable will always refer to an object of its declared class — an expanded variable cannot receive objects in assignments. Then, in particular, they cannot receive objects of subclasses which do not have a particular init method. If clock were a regular variable and “clock.init(13, 52)” were legal, a runtime type error could occur. Variable clock could refer to an object whose class does not define an init method. These methods never belong, by definition, to a class type, which is the set of public method signatures. Expanded variables always refer to the same object at runtime. This allows the compiler to optimize message sends to them. No runtime search for a method is necessary — a method call is made as efficient as a regular procedure call in procedural languages. There should not be any cycles in the classes of expanded variables. That is, it is illegal a class A declare an expanded variable of class B and class B declare an expanded variable of class A.

برای دانلود رایگان متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

A Two-Stage Green Supply Chain Network with a Carbon Emission Price by a Multi-objective Interior Search Algorithm

This paper presented a new two-stage green supply chain network, in which includes two innovations. Firstly, it presents a new multi-objective model for a two-stage green supply chain problem that considers the amount o...

متن کامل

An Efficient Green Approach for the Synthesis of Structurally Diversified Spirooxindoles Using Sulfonic Acid Functionalized Nanoporous Silica (SBA-Pr-SO3H)

One-pot multicomponent reaction between isatin, barbituric acid, and 6-amino-1,3-dimethyl uracil was investigated <span style="font-size: 10.0pt; ...

متن کامل

The relationship between working memory and L2 reading comprehension

Since  an  important  role  for  working  memory  has  been  found  in  the  first  language acquisition  (e.g.,  Daneman,  1991;  Daneman  &  Green,  1986;  Waters  &  Caplan,  1996), research  on  the  role  of  working  memory  is  emerging  as  an  area  of  concern  for  second language  acquisition  (e.g.,  Atkins  &  Baddeley,  1998;  Miyake  &  Freidman,  1998; Robinson,  1995,  2002,  ...

متن کامل

The green beards of language

Language transfers information on at least three levels; (1) what is said, (2) how it is said (what language is used), and, (3) that it is said (that speaker and listener both possess the ability to use language). The use of language is a form of honest cooperation on two of these levels; not necessarily on what is said, which can be deceitful, but always on how it is said and that it is said. ...

متن کامل

Graph DSLs : A Survey on Green-Marl & Sparql

Many real world problems are formulated as graphs and standard graph processing algorithms are used to search solutions. Applications of graphs and related algorithms can be found in many domains. Domains vary from standard scientific applications to social media applications such as facebook. Creating and processing graphs in HPC environments adds lot of complexities. Hiding detail complexitie...

متن کامل

When Visual Programs are Harder to Read than Textual Programs

Claims for the virtues of visual programming languages have generally been strong, simple-minded statements that visual programs are inherently better than textual ones. They have paid scant attention to previous empirical literature showing difficulties in comprehending visual programs. This paper reports comparisons between the comprehensibility of textual and visual programs, drawing on the ...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

عنوان ژورنال:
  • Computer Languages, Systems & Structures

دوره 32  شماره 

صفحات  -

تاریخ انتشار 2006